<?php echo $html->script('act_lists', array('inline' => false));?>
<?php echo $html->css('act_lists', 'stylesheet', array('inline' => false));?>
<div class="<?=$this->params['controller']?> <?=$html->action?>">
<?php echo $form->create('ActList', array('action' => 'edit'));?>
	<fieldset>
 		<legend><?php __('Edit Kegiatan Harian');?></legend>
        <table class="input">
            <tr>
                <td colspan="2">
                    <table>
                        <tr>
                            <td class="label">Nama</td>
                            <td class="val"><?php echo $creator_name;?></td>
                        </tr>
                        <tr>
                            <td class="label">Jabatan</td>
                            <td class="val"><?php echo $my_position;?></td>
                        </tr>
                        <tr>
                            <td class="label">Aktifitas pada tanggal</td>
                            <td class="val"><?php echo $time->format('d/m/Y', $activity_date);?></td>
                        </tr>
                        <tr>
                            <td class="label">Verifikator</td>
                            <td class="val"><?php echo $verificator_position;?></td>
                        </tr>
                        <?php if (!$not_user):?>
                        <tr>
                            <td class="label">Verifikasi Kehadiran</td>
                            <td class="val">
                            <?php
                                echo $absent_options[$absent];
                            ?>
                            </td>
                        </tr>
                        <?php endif;?>
                    </table>
                </td>
            </tr>
            <?php if ($not_user):?>
            <tr>
                <td colspan="2">
                    <div class="flash_box flash_info">
                    Saya sebagai verifikator menyetujui untuk memverifikasi kegiatan bawahan saya
                    dengan sebenar-benarnya.<br />Sebagai verifikator hal yang perlu dilakukan : <br />
                    1. Set kehadiran pada tanggal aktifitas.<br />
                    2. Jika kegiatan benar, lakukan centang pada kolom Verifikasi kebenaran.
                    </ol>
                    </div>
                    Absensi <?php echo $creator_name;?> pada tanggal <?php echo $time->format('d/m/Y', $activity_date);?> : &nbsp;
                    <?php
                    echo $form->select('absent', $absent_options, null,
                        array('div' => false, 'label' => false, 'empty' => false)
                    );
                    ?>
                </td>
            </tr>
            <?php endif;?>
            <tr>
                <td colspan="2">
                    <table id="list_activities" class="list_activities">
                        <thead>
                            <tr>
                                <th>&nbsp;</th>
                                <th>Kegiatan</th>
                                <th colspan="2" class="center">Sub Kegiatan</th>
                                <th>No Surat Tugas</th>
                                <th>Produk / Hasil</th>
                                <th>Verifikasi Kebenaran</th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php if ( isset($lists) ): ?>
                        <?php
                            $enable_to_verify_all = true;
                            $enable_to_verify = true;
                            foreach ($lists['ActListActivity'] as $key => $list_activity):
                                echo '<tr class="row_list_activities" id="r'.$key.'" rel="r'.$key.'_d0">';
                                    echo '<td>';
                                    if ($not_user):
                                        // hide it
                                        echo '<input type="hidden" name="data[ActList][ActListActivity]['. $key .
                                             '][id]" class="cb_list_activities" class="inputText" />';
                                    else:
                                        echo '<input type="checkbox" name="data[ActList][ActListActivity]['. $key .
                                             '][id]" class="cb_list_activities" class="inputText" />';
                                    endif;
                                    echo '</td>';
                                    echo '<td>';
                                    if ($not_user):
                                        echo $activities[ $list_activity['activity_id'] ];
                                        // hide it
                                        echo $form->input('activity_id', array(
                                            'id' => null, 'class' => 'activity_id',
                                            'name' => 'data[ActList][ActListActivity]['.$key.'][activity_id]',
                                            'type' => 'hidden', 'value' => $list_activity['activity_id']
                                        ));
                                    else:
                                        echo $form->select('activity_id', $activities, $list_activity['activity_id'], array(
                                            'id' => null, 'class' => 'activity_id',
                                            'name' => 'data[ActList][ActListActivity]['.$key.'][activity_id]',
                                            'empty' => false
                                        ));
                                    endif;
                                    echo '</td>';
                                    echo '<td>';
                                    if ($not_user):
                                        echo '&nbsp;';
                                    else:
                                        echo $html->image('cross.png', array(
                                            'alt' => 'Klik untuk menghapus sub kegiatan',
                                            'rel' => 'r'.$key.'_d0',
                                            'class' => 'del_description'
                                        ));
                                    endif;
                                    echo '</td>';
                                    echo '<td>';
                                    if ($not_user):
                                        echo $list_activity['ActListActivityDescription'][0]['description'];
                                        // hide it
                                        echo $form->input('description',
                                            array(
                                                'id' => null,
                                                'name' => 'data[ActList][ActListActivity]['.$key.'][ActListActivityDescription][0][description]',
                                                'class' => 'inputText description',
                                                'type' => 'hidden', 'div' => false, 'label' => false,
                                                'value' => $list_activity['ActListActivityDescription'][0]['description']
                                            )
                                        );
                                    else:
                                        echo $form->input('description',
                                            array(
                                                'id' => null,
                                                'name' => 'data[ActList][ActListActivity]['.$key.'][ActListActivityDescription][0][description]',
                                                'class' => 'inputText description',
                                                'type' => 'textarea', 'div' => false, 'label' => false,
                                                'value' => $list_activity['ActListActivityDescription'][0]['description']
                                            )
                                        );
                                    endif;
                                    echo '</td>';
                                    
                                    echo '<td>';
                                    if ($not_user):
                                        echo $list_activity['ActListActivityDescription'][0]['assignment_no'];
                                        // hide it
                                        echo $form->input('assignment_no', array(
                                            'div' => false, 'label' => false,
                                            'id' => null, 'class' => 'inputText assignment_no',
                                            'name' => 'data[ActList][ActListActivity]['.$key.'][ActListActivityDescription][0][assignment_no]',
                                            'type' => 'hidden',
                                            'value' => $list_activity['ActListActivityDescription'][0]['assignment_no']
                                        ));
                                    else:
                                        echo $form->input('assignment_no', array(
                                            'div' => false, 'label' => false,
                                            'id' => null, 'class' => 'inputText assignment_no',
                                            'name' => 'data[ActList][ActListActivity]['.$key.'][ActListActivityDescription][0][assignment_no]',
                                            'value' => $list_activity['ActListActivityDescription'][0]['assignment_no']
                                        ));
                                    endif;
                                    echo '</td>';
                                    
                                    echo '<td>';
                                    if ($not_user):
                                        if ( empty($list_activity['ActListActivityDescription'][0]['result']) ) {
                                            $enable_to_verify = false;
                                            $enable_to_verify_all = false;
                                        } else {
                                            $enable_to_verify = true;
                                        }
                                        
                                        // hide it
                                        echo $form->input('result', array(
                                            'div' => false, 'label' => false,
                                            'id' => null, 'class' => 'inputText result',
                                            'name' => 'data[ActList][ActListActivity]['.$key.'][ActListActivityDescription][0][result]',
                                            'type' => 'textarea',
                                            'value' => $list_activity['ActListActivityDescription'][0]['result']
                                        ));
                                    else:
                                        echo $form->input('result',
                                            array(
                                                'id' => null,
                                                'name' => 'data[ActList][ActListActivity]['.$key.'][ActListActivityDescription][0][result]',
                                                'class' => 'inputText result',
                                                'type' => 'textarea', 'div' => false, 'label' => false,
                                                'value' => $list_activity['ActListActivityDescription'][0]['result']
                                            )
                                        );
                                    endif;
                                    echo '</td>';
                                    
                                    
                                    echo '<td class="center">';
                                    if ($not_user):
                                        if ( $enable_to_verify ):
                                            echo '<input type="checkbox" value="1"' .
                                                ' name="data[ActList][ActListActivity]['.$key.'][ActListActivityDescription][0][verified]"'.
                                                ' class="inputText verified"' .
                                                ($list_activity['ActListActivityDescription'][0]['verified'] ? ' checked="checked"' : '') .
                                                ' />';
                                        else:
                                            echo  '<span class="red">Hasil/produk kosong</span>';
                                        endif;
                                    else:
                                        echo $list_activity['ActListActivityDescription'][0]['verified'] ?
                                             '<span class="green">Sudah diverifikasi</span>' :
                                             '<span class="red">Belum diverifikasi</span>';
                                    endif;
                                    echo '</td>';
                                echo '</tr>';
                                
                                // cek list_activity_description and make sure > 1
                                if (!empty($list_activity['ActListActivityDescription']) && count($list_activity['ActListActivityDescription']) > 1) {
                                    // iterate each description
                                    foreach ($list_activity['ActListActivityDescription'] as $key2 => $list_activity_description):
                                        if ($key2 === 0) {
                                            continue;
                                        }
                                        
                                        echo '<tr class="row_list_activity_descriptions" id="r'.$key.'_d'.$key2.'" rel="r'.$key.'_d'.$key2.'">';
                                        echo '<td class="empty">&nbsp;</td>';
                                        echo '<td class="empty">&nbsp;</td>';
                                        echo '<td>';
                                        if ($not_user):
                                            echo '&nbsp;';
                                        else:
                                            echo $html->image('cross.png', array(
                                                'alt' => 'Klik untuk menghapus sub kegiatan',
                                                'rel' => 'r'.$key.'_d'.$key2,
                                                'class' => 'del_description'
                                            ));
                                        endif;
                                        echo '</td>';
                                        
                                        echo '<td>';
                                        if ($not_user):
                                            echo $list_activity_description['description'];
                                            // hide it
                                            echo $form->input('description',
                                                array(
                                                    'id' => null,
                                                    'name' => 'data[ActList][ActListActivity]['.$key.'][ActListActivityDescription]['.$key2.'][description]',
                                                    'class' => 'inputText description',
                                                    'type' => 'hidden', 'div' => false, 'label' => false,
                                                    'value' => $list_activity_description['description']
                                                )
                                            );
                                        else:
                                            echo $form->input('description',
                                                array(
                                                    'id' => null,
                                                    'name' => 'data[ActList][ActListActivity]['.$key.'][ActListActivityDescription]['.$key2.'][description]',
                                                    'class' => 'inputText description',
                                                    'type' => 'textarea', 'div' => false, 'label' => false,
                                                    'value' => $list_activity_description['description']
                                                )
                                            );
                                        endif;
                                        echo '</td>';
                                        
                                        echo '<td>';
                                        if ($not_user):
                                            echo $list_activity_description['assignment_no'];
                                            // hide it
                                            echo $form->input('assignment_no', array(
                                                'div' => false, 'label' => false,
                                                'id' => null, 'class' => 'inputText assignment_no', 'type' => 'hidden',
                                                'name' => 'data[ActList][ActListActivity]['.$key.'][ActListActivityDescription]['.$key2.'][assignment_no]',
                                                'value' => $list_activity_description['assignment_no']
                                            ));
                                        else:
                                            echo $form->input('assignment_no', array(
                                                'div' => false, 'label' => false,
                                                'id' => null, 'class' => 'inputText assignment_no',
                                                'name' => 'data[ActList][ActListActivity]['.$key.'][ActListActivityDescription]['.$key2.'][assignment_no]',
                                                'value' => $list_activity_description['assignment_no']
                                            ));
                                        endif;
                                        echo '</td>';
                                        
                                        echo '<td>';
                                        if ($not_user):
                                            if ( empty($list_activity['ActListActivityDescription'][0]['result']) ) {
                                                $enable_to_verify = false;
                                                $enable_to_verify_all = false;
                                            } else {
                                                $enable_to_verify = true;
                                            }
                                            
                                            echo $form->input('result',
                                                array(
                                                    'id' => null,
                                                    'name' => 'data[ActList][ActListActivity]['.$key.'][ActListActivityDescription]['.$key2.'][result]',
                                                    'class' => 'inputText result',
                                                    'type' => 'textarea', 'div' => false, 'label' => false,
                                                    'value' => $list_activity_description['result']
                                                )
                                            );
                                        else:
                                            echo $form->input('result',
                                                array(
                                                    'id' => null,
                                                    'name' => 'data[ActList][ActListActivity]['.$key.'][ActListActivityDescription]['.$key2.'][result]',
                                                    'class' => 'inputText result',
                                                    'type' => 'textarea', 'div' => false, 'label' => false,
                                                    'value' => $list_activity_description['result']
                                                )
                                            );
                                        endif;
                                        echo '</td>';
                                        
                                        echo '<td class="center">';
                                        if ($not_user):
                                            if ($enable_to_verify):
                                                echo '<input type="checkbox" value="1"' .
                                                    ' name="data[ActList][ActListActivity]['.$key.'][ActListActivityDescription]['.$key2.'][verified]"' .
                                                    ' class="inputText verified"' .
                                                    ($list_activity_description['verified'] ? ' checked="checked"' : '') .
                                                    ' />';
                                            else:
                                                echo '<span class="red">Hasil/produk kosong</span>';
                                            endif;
                                        else:
                                            echo $list_activity_description['verified'] ?
                                                 '<span class="green">Sudah diverifikasi</span>' :
                                                 '<span class="red">Belum diverifikasi</span>';
                                        endif;
                                        echo '</td>';
                                        echo '</tr>';
                                    endforeach;
                                } // eof check list_activity_description
                                
                                // add .add_description row (latest row)
                                echo '<tr id="rg'.$key.'" class="add_description_row">' .
                                     '<td colspan="2">&nbsp;</td>';
                                echo '<td colspan="5">';
                                if ($not_user):
                                    echo '&nbsp;';
                                else:
                                    echo '<span class="up"></span>';
                                    echo '<input type="button" class="add_description" id="b'.$key.'" value="+ Tambah sub kegiatan" />';
                                endif;
                                echo '</td></tr>';
                            endforeach; // eof list_activity
                        ?>
                        <?php else: ?>
                            <tr class="row_list_activities" id="r0" rel="r0_d0">
                                <td>
                                    <input type="checkbox" name="data[ActList][ActListActivity][0][id]" class="cb_list_Activities" class="inputText" />
                                </td>                         
                                <td> 
                                    <?php 
                                        echo $form->select(
                                        'activity_id', $activities, null,
                                        array(
                                            'id' => null,
                                            'class' => 'activity_id',
                                            'name' => 'data[ActList][ActListActivity][0][activity_id]',
                                            'empty' => false
                                        ));
                                    ?>
                                </td>
                                <td>
                                    <?php
                                        echo $html->image('cross.png', array(
                                            'alt' => 'Klik untuk menghapus sub kegiatan',
                                            'rel' => 'r0_d0',
                                            'class' => 'del_description'
                                        ));
                                    ?>
                                </td>
                                <td>
                                    <?php
                                        echo $form->input('description',
                                            array(
                                                'id' => null,
                                                'name' => 'data[ActList][ActListActivity][0][ActListActivityDescription][0][description]',
                                                'class' => 'inputText description',
                                                'type' => 'textarea', 'div' => false, 'label' => false
                                            )
                                        );
                                    ?>
                                </td>
                                <td>
                                    <?php
                                        echo $form->input('assignment_no', array(
                                            'div' => false, 'label' => false,
                                            'id' => null, 'class' => 'inputText assignment_no',
                                            'name' => 'data[ActList][ActListActivity][0][ActListActivityDescription][0][assignment_no]'
                                        ));
                                    ?>
                                </td>
                                <td>
                                    <?php
                                        echo $form->input('result', array(
                                            'div' => false, 'label' => false,
                                            'id' => null, 'class' => 'inputText result',
                                            'name' => 'data[ActList][ActListActivity][0][ActListActivityDescription][0][result]'
                                        ));
                                    ?>
                                </td>
                            </tr>
                            <tr id="rg0" class="add_description_row">
                                <td colspan="2">&nbsp;</td>
                                <td colspan="3">
                                    <span class="up"></span>
                                    <input type="button" class="add_description" id="b0" value="+ Tambah sub kegiatan" />
                                </td>
                            </tr>
                        <?php endif;?>
                        </tbody>
                        <?php if (!$not_user):?>
                        <tfoot>
                            <tr>
                                <th>&nbsp;</th>
                                <th colspan="6">
                                    <span class="up"></span>
                                    <input type="button" name="add_row" id="add_row" value="+ Tambah Kegiatan" /> &nbsp; atau &nbsp;
                                    <input type="button" name="del_row" id="del_row" value="- Hapus Kegiatan" />
                                </th>
                            </tr>
                        </tfoot>
                        <?php endif;?>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                <?php
                    //if ($enable_to_verify_all):
                    echo $form->submit('Simpan Aktifitas ini', array('div'=>false)) . "&nbsp;" . __('or', true) . "&nbsp;";
                    //endif;
                    echo $html->link(__('Back', true), array('action'=>'index'), array('class'=>'back'));
                ?>
                </td>
            </tr>
        </table>
	</fieldset>
</form>	
</div>
<?php if (isset($action_suffix)): // if we are editing from verify list ?>
<script type="text/javascript">
$(function() {
    var action_suffix = '?<?php echo $action_suffix;?>=1';
    var action = $('#ActListEditForm').attr('action');
    
    $('#ActListEditForm').attr('action', action + action_suffix);
});
</script>
<?php endif;?>
